package com.baor.dao;

import com.baor.domain.Equipment;
import com.baor.domain.Equipment_instructions;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface Equipment_instructionsDao extends MPJBaseMapper<Equipment_instructions> {

    /**
     * 查询所有设备
     */
    @Select("SELECT id, code, address FROM equipment WHERE is_deleted = 0")
    List<Equipment> selectAllEquipment();

    /**
     * 根据设备ID查询设备
     */
    @Select("SELECT * FROM equipment WHERE id = #{id} AND is_deleted = 0")
    Equipment selectById(Integer id);

    @Update("UPDATE equipment_instructions SET status = 1, updated_at = NOW() " +
            "WHERE scheduled_execution_time <= #{currentTime} " +
            "AND status = 0 " +
            "AND is_deleted = 0")
    int updateExpiredInstructions(@Param("currentTime") String currentTime);
}